//
//  USChatCellFactory.m
//  us
//
//  Created by karry on 2025/4/6.
//

#import "USChatCellFactory.h"

@implementation USChatCellFactory

+ (void)registerAllCellsForTableView:(UITableView *)tableView {
    [tableView registerClass:[USChatTextCell class] forCellReuseIdentifier:@"USChatTextCell"];
    [tableView registerClass:[USChatImageCell class] forCellReuseIdentifier:@"USChatImageCell"];
    [tableView registerClass:[USChatVoiceCell class] forCellReuseIdentifier:@"USChatVoiceCell"];
    [tableView registerClass:[USChatCell class] forCellReuseIdentifier:@"USChatCell"];
    [tableView registerClass:[USChatEmojiCell class] forCellReuseIdentifier:@"USChatEmojiCell"];
    [tableView registerClass:[USChatRecallCell class] forCellReuseIdentifier:@"USChatRecallCell"];

}

+ (USChatCell*)cellForViewModel:(USMessageViewModel *)vm
                                              tableView:(UITableView *)tableView
                                             indexPath:(NSIndexPath *)indexPath {
    NSString *identifier = nil;
    switch (vm.message.body.type) {
        case EMMessageBodyTypeText:
            identifier = @"USChatTextCell";break;
        case EMMessageBodyTypeImage:
            identifier = @"USChatImageCell";break;
        case EMMessageBodyTypeVoice:
            identifier = @"USChatVoiceCell";break;
        case EMMessageBodyTypeCustom: {
            //自定义消息
            EMCustomMessageBody *body = (EMCustomMessageBody *)vm.message.body;
            if ([body.event isEqualToString:@"emoji"]) {
                identifier = @"USChatEmojiCell";
            }else if ([body.event isEqualToString:@"recall"]) {
                identifier = @"USChatRecallCell";
            }else {
                NSLog(@"message.body  =  %@",vm.message.ext);

                identifier = @"USChatCell";
            }
             break;
        }

        default:
            identifier = @"USChatTextCell"; break;
    }
    
    USChatCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    
    cell.messageViewModel = vm;
    
    return cell;
    
}

@end
